library Broadcast initializer init requires LegacySystem

	private function Trig_Broadcast_Conditions takes nothing returns boolean 
		  if( GetSpellAbilityId()=='A03N') then 
			   return true
		  elseif(GetSpellAbilityId()=='A030') then
			   return true
		  endif
		  return false
	endfunction

	private function MedicalBroadcast takes nothing returns nothing
		local integer i = GetItemTypeId(GetEnumItem())
		if i=='phea' or i=='I004' or i=='I00J' then
			call PingMinimapEx(GetItemX(GetEnumItem()), GetItemY(GetEnumItem()), 6.0, 51, 179, 51, false)
		endif
	endfunction

	private function MunitionsBroadcast takes nothing returns nothing
		local integer i = GetItemTypeId(GetEnumItem())
		if i=='shas' or i=='I006' or i=='I00C' or i=='I00D' then
			call PingMinimapEx(GetItemX(GetEnumItem()), GetItemY(GetEnumItem()), 6.0, 101, 51, 129, false)
		endif
	endfunction

	private function BroadcastBeacons takes nothing returns nothing
		local real x = GetUnitX(GetTriggerUnit())
		local real y = GetUnitY(GetTriggerUnit())
		local rect r = Rect(x-3250.0, y-3250.0, x+3250.0, y+3250.0)
		if GetSpellAbilityId()=='A03N' then
			call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 3.0, "Broadcasting Medical Supply Beacons.." )
			call EnumItemsInRect( r, null, function MedicalBroadcast )
		elseif GetSpellAbilityId()=='A030' then
			call DisplayTimedTextToPlayer( GetLocalPlayer(), 0, 0, 3.0, "Broadcasting Munitions Beacons.." )
			call EnumItemsInRect( r, null, function MunitionsBroadcast )
		endif
		call RemoveRect(r)
		set r = null
	endfunction

	private function init takes nothing returns nothing
		local trigger t
		set t = CreateTrigger(  )
		call TriggerRegisterAnyUnitEventBJ( t,  EVENT_PLAYER_UNIT_SPELL_EFFECT  )
		call TriggerAddCondition( t, Condition( function Trig_Broadcast_Conditions ) )
		call TriggerAddAction( t, function BroadcastBeacons )
		
	endfunction

endlibrary

